package com.sheng.whyclass.person.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.sheng.whyclass.R;


public final class MainActNavigateView extends FrameLayout implements View.OnClickListener {

    public static final class Component {
        public static final byte NAVIGATE_STUDENT_INFO = 1;
        public static final byte NAVIGATE_WORK_UNFINISH = 2;
        public static final byte NAVIGATE_WORK_FINISHED = 3;
        public static final byte NAVIGATE_ANSWER = 4;
    }

    public static interface ICallback {
        void onClicked(byte component);
    }

    private ImageView personIV;
    private ImageView workUnfinishedIV;
    private ImageView workFinishedIV;
    private ImageView answerIV;


    private ICallback mCallback;

    public MainActNavigateView(Context context) {
        this(context, null);
    }

    public MainActNavigateView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MainActNavigateView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        LayoutInflater.from(context).inflate(R.layout.main_act_navigate_layout, this);

        personIV = (ImageView) findViewById(R.id.personIV);
        workUnfinishedIV = (ImageView) findViewById(R.id.workUnFinishIV);
        workFinishedIV = (ImageView) findViewById(R.id.workFinishedIV);
        answerIV = (ImageView) findViewById(R.id.answerIV);

        findViewById(R.id.personFrame).setOnClickListener(this);
        findViewById(R.id.workUnFinishFrame).setOnClickListener(this);
        findViewById(R.id.workFinishedFrame).setOnClickListener(this);
        findViewById(R.id.answerFrame).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (mCallback == null) {
            return;
        }

        switch (v.getId()) {
            case R.id.personFrame: {
                mCallback.onClicked(Component.NAVIGATE_STUDENT_INFO);
                break;
            }
            case R.id.workUnFinishFrame:{
                mCallback.onClicked(Component.NAVIGATE_WORK_UNFINISH);
                break;
            }
            case R.id.workFinishedFrame: {
                mCallback.onClicked(Component.NAVIGATE_WORK_FINISHED);
                break;
            }
            case R.id.answerFrame: {
                mCallback.onClicked(Component.NAVIGATE_ANSWER);
                break;
            }
        }
    }

    public void setCallback(ICallback callback) {
        mCallback = callback;
    }

    public void setSelected(byte component) {
        switch (component) {
            case Component.NAVIGATE_STUDENT_INFO: {
                personIV.setImageResource(R.drawable.person_selected);
                workUnfinishedIV.setImageResource(R.drawable.work_unfinish_unselected);
                workFinishedIV.setImageResource(R.drawable.work_finished_unselected);
                answerIV.setImageResource(R.drawable.answer_unselected);
                break;
            }
            case Component.NAVIGATE_WORK_UNFINISH: {
                personIV.setImageResource(R.drawable.person_unselected);
                workUnfinishedIV.setImageResource(R.drawable.work_unfinish_selected);
                workFinishedIV.setImageResource(R.drawable.work_finished_unselected);
                answerIV.setImageResource(R.drawable.answer_unselected);
                break;
            }
            case Component.NAVIGATE_WORK_FINISHED: {
                personIV.setImageResource(R.drawable.person_unselected);
                workUnfinishedIV.setImageResource(R.drawable.work_unfinish_unselected);
                workFinishedIV.setImageResource(R.drawable.work_finished_selected);
                answerIV.setImageResource(R.drawable.answer_unselected);
                break;
            }
            case Component.NAVIGATE_ANSWER: {
                personIV.setImageResource(R.drawable.person_unselected);
                workUnfinishedIV.setImageResource(R.drawable.work_unfinish_unselected);
                workFinishedIV.setImageResource(R.drawable.work_finished_unselected);
                answerIV.setImageResource(R.drawable.answer_selected);
                break;
            }
        }
    }
}
